package com.forum.message.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.forum.message.model.entity.Message;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 消息Mapper接口
 */
@Mapper
public interface MessageMapper extends BaseMapper<Message> {
    
    /**
     * 查询用户消息（已读/未读过滤）
     */
    IPage<Message> selectUserMessages(Page<Message> page, 
                                     @Param("receiverId") Long receiverId, 
                                     @Param("isRead") Boolean isRead, 
                                     @Param("type") String type);
    
    /**
     * 统计用户未读消息数量
     */
    long countUnreadMessages(@Param("receiverId") Long receiverId, 
                            @Param("type") String type);
    
    /**
     * 批量标记消息为已读
     */
    int markAllAsRead(@Param("receiverId") Long receiverId, 
                     @Param("type") String type, 
                     @Param("readTime") LocalDateTime readTime);
    
    /**
     * 批量删除指定接收者的消息
     */
    int deleteAllByReceiverId(@Param("receiverId") Long receiverId);
    
    /**
     * 查找最近一定时间内的相似消息
     */
    List<Message> findRecentSimilarMessages(@Param("receiverId") Long receiverId, 
                                          @Param("type") String type, 
                                          @Param("resourceType") String resourceType, 
                                          @Param("since") LocalDateTime since);
} 